#!/bin/csh -f
set echo_style=both
set USAGE="USAGE: para2para CONFIG\nTransfers positional parameters from CONFIG (copa-type file) to INPUT/ap.def (must exist!)"
if ( $# == 0) then
    echo $USAGE | fold -s -w 70
    exit
endif
if (! -e $1 ) then
    echo "File $1 (expect copa-type) does not exist."
    echo "------------------------------------------"
    echo $USAGE | fold -s -w 70
    exit
endif
if (! -e INPUT/ap.def ) then
    echo "File INPUT/ap.def does not exist. Cannot transfer!"
    echo "------------------------------------------"
    echo $USAGE | fold -s -w 70
    exit
endif

if (! -e $DECAHOME/SRC/para2para.awk) then
    echo "Missing file $DECAHOME/SRC/para2para.awk - perhaps DECAHOME not set?"
    exit
endif
awk -f $DECAHOME/SRC/para2para.awk $1 INPUT/ap.def > ap.tmp
set ap=`wc -l ap.tmp`
if( $ap[1] == 0 )then
    #expect error printed on stderr by para2para.awk...
    rm ap.tmp
else
    echo "Moving INPUT/ap.def -> INPUT/ap.def~\nTransferring parameters from $1 -> INPUT/ap.def" 
    mv INPUT/ap.def INPUT/ap.def~
    mv ap.tmp INPUT/ap.def
endif
##

